package asteroids.model.expressions;

import exceptions.IllegalOperandException;

/**
 * A subclass of expression (E) that represents the division (/) of two doubles
 * 
 * @version 1.0
 * 
 * @author	Thijs Peirelinck & Wouter Parys
 *
 */
public class Division extends Operation {

	public Division(E e1, E e2) {
		super(e1, e2);
	}
	
	@Override
	public Division createCopy() {
		return new Division(getLeftOperand().createCopy(), getRightOperand().createCopy());
	}

	@Override
	public Double getValue() throws IllegalOperandException {
		if(this.isValidExpression() == false) { throw new IllegalOperandException(); } 
		double left = ((Double)getLeftOperand().getValue()).doubleValue();
		double right = ((Double)getRightOperand().getValue()).doubleValue();
		return left/right;

	}
	
	@Override
	public String toString() {
		return getLeftOperand().toString() + " / " + getRightOperand().toString();
	}
}
